package com.laker.admin.module.excel.facade.impl;

import com.laker.admin.framework.model.Response;
import com.laker.admin.module.excel.application.ExcelDataSourceApplication;
import com.laker.admin.module.excel.domain.ExcelDataSource;
import com.laker.admin.module.excel.facade.ExcelDataSourceFacade;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author nihongxin
 * @date 2021/12/14
 * @description
 */
@Service
public class ExcelDataSourceFacadeImpl implements ExcelDataSourceFacade {

    @Resource
    private ExcelDataSourceApplication excelDataSourceApplication;


    @Override
    public Response save(ExcelDataSource excelDataSource) {
        try {
            ExcelDataSource excelDataSourceCheck = excelDataSourceApplication.getExcelDataSourceByCheck(excelDataSource);
            if (null == excelDataSourceCheck) {
                excelDataSourceApplication.save(excelDataSource);
            } else {
                excelDataSource.setId(excelDataSourceCheck.getId());
                excelDataSourceApplication.save(excelDataSource);
            }
            return Response.ok();
        } catch (Exception e) {
            return Response.error(e.getMessage());
        }
    }
}
